<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<style>
		.div-date-picker {
			position: relative;
		}
		#datetime-picker {
			padding-left: 24px;
		}
		#time-picker {
			padding-left: 24px;
		}
		.div-date-picker .fa-calendar, .fa-clock-o {
			position: absolute;
			left: 18px;
			top: 10px;
		}
		.form-group-sdk .switch-open-close input[type="checkbox"].ace.ace-switch.ace-switch-7:checked + .lbl::before {
			content: "增值版";
		}
		.form-group-sdk .switch-open-close input[type="checkbox"].ace.ace-switch.ace-switch-7 + .lbl::before {
			content: "免费版";
		}
		.form-group-sdk .switch-open-close input[type=checkbox].ace.ace-switch.ace-switch-7 + .lbl::before {
			width: 85px
		}
		.form-group-sdk .switch-open-close input[type=checkbox].ace.ace-switch.ace-switch-7 + .lbl::before {
			width: 85px
		}

		.form-group-sdk .switch-open-close input[type=checkbox].ace.ace-switch.ace-switch-7 + .lbl::after {
    		left: 55px;
		}
		.form-group-sdk .switch-open-close input[type=checkbox].ace.ace-switch.ace-switch-7:checked + .lbl::after {
    		left: 0;
		}
	</style>
	<div class="page-header">
		<h1><?=$schoolId ? '编辑学校信息' : '新增学校'?></h1>
	</div>

	<div class="col-xs-12">
		<form class="form-horizontal" id="school-form">
			<input type="hidden" name="id" value="<?=$schoolInfo['id']?>" />
			<input type="hidden" name="school_from" value="<?=$schoolFrom?>" />

			<?php if($schoolFrom == X_DATA_HAOZHUANYE): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">学校ID：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_id" placeholder="请填写接口学校ID" value="<?=$schoolInfo['school_x_id']?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">接口login参数：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_params" placeholder="请填写接口login参数" value="<?=$schoolInfo['school_x_params']?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">接口token参数：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_token" placeholder="请填写接口token参数" value="<?=$schoolInfo['school_x_token']?>" />
					</div>
				</div>
			<?php elseif($schoolFrom == X_DATA_YINTONG): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">	第三方应用id：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_id" placeholder="请填写银通接口第三方应用id" value="<?=$schoolInfo['school_x_id']?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">法人编码：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_params" placeholder="请填写银通接口法人编码" value="<?=$schoolInfo['school_x_params']?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">密钥：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_token" placeholder="请填写银通接口密钥" value="<?=$schoolInfo['school_x_token']?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">是否分校区：</label>
					<div class="col-sm-6">
						<select class="form-control" name="muti_campus">
							<option value="0" <?= $mutiCampus == 0 ? "selected" : "" ?>>否</option>
							<option value="1" <?= $mutiCampus == 1 ? "selected" : "" ?>>是</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">学校名称：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_name" placeholder="请填写学校名称" value="<?=$schoolInfo['school_name']?>" />
					</div>
				</div>
			<?php elseif($schoolFrom == X_DATA_CHAOXING): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">超星学校id：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_id" placeholder="请填写超星学校id" value="<?=$schoolInfo['school_x_id']?>" />
					</div>
				</div>
			<?php elseif($schoolFrom == X_DATA_FEICHEN): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">斐宸学校id：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_x_id" placeholder="请填写斐宸学校id" value="<?=$schoolInfo['school_x_id']?>" />
					</div>
				</div>
			<?php endif; ?>

			<?php if(!$schoolFrom): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">学校名称：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_name" placeholder="请填写学校名称" value="<?=$schoolInfo['school_name']?>" />
					</div>
				</div>
			<?php endif; ?>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">学校行政区划：</label>
				<div class="col-sm-2">
					<select class="form-control" name="school_province" id="province-select">
						<?php foreach($province as $item):?>
							<option value="<?=$item['area_code']?>"><?=$item['area_name']?></option>
						<?php endforeach; ?>
					</select>
				</div>
				<div class="col-sm-2">
					<select class="form-control" name="school_city" id="city-select">
						<option value="0">请选择学校所属地级行政区</option>
					</select>
				</div>
				<div class="col-sm-2">
					<select class="form-control" name="school_area" id="area-select">
						<option value="0">请选择学校所属县级行政区</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班牌主题：</label>
				<div class="col-sm-6">
					<select class="form-control" name="brand_theme">
						<?php foreach($themes as $theme): ?>
							<option value="<?= $theme['name'] ?>"><?= $theme['chineseName'] ?></option>
						<?php endforeach ?>
					</select>
				</div>
			</div>
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">校训：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="school_motto" placeholder="" value="<?=$schoolInfo['school_motto']?>" />
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">人脸识别模块：</label>
				<div class="col-sm-6">
					<select class="form-control" name="school_face_detect">
						<?php foreach($faceList as $face): ?>
							<option value="<?= $face['value'] ?>"><?= $face['title'] ?></option>
						<?php endforeach ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">测温模块类型：</label>
				<div class="col-sm-6">
					<select class="form-control" name="school_face_detect_type">
						<option value="0">默认</option>
						<option value="1">MLX32X32</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">班牌版本更新：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="school_brand_update" class="ace ace-switch ace-switch-7" type="checkbox" checked="" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">考务模块：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="school_exam" class="ace ace-switch ace-switch-7" type="checkbox" checked="" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">智能门锁：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="school_smart_lock" class="ace ace-switch ace-switch-7" type="checkbox" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group form-group-sdk">
				<label class="col-sm-3 control-label no-padding-right">SDK版本：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="face_sdk" class="ace ace-switch ace-switch-7" type="checkbox" checked="" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">教师考勤：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="enable_teacher_sign" class="ace ace-switch ace-switch-7" type="checkbox" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-sm-3 control-label no-padding-right">过期时间：</label>
				<div class="col-sm-6 div-date-picker">
					<input class="form-control" id="datetime-picker" type="text" name="expire_date" placeholder="请选择过期时间" />
					<i class="fa fa-calendar"></i>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">定时通知过期家长（0:00即为关闭通知）：</label>
				<div class="col-sm-6 div-date-picker">
					<input class="form-control" id="time-picker" type="text" name="notify_expire_time" placeholder="请选择通知时间" value="<?=$schoolInfo['notify_expire_time'] ? $schoolInfo['notify_expire_time'] : ' ' ?>" />
					<i class="fa fa-clock-o"></i>
					<!-- <i class="fa fa-calendar"></i> -->
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">人脸识别相似度：</label>
				<div class="col-sm-6">
					<input class="form-control" type="number" name="face_similar" step="0.01" placeholder="人脸相似度，0.1~0.9" value="<?=$schoolInfo['face_similar'] ? $schoolInfo['face_similar'] : 0.9 ?>" />
				</div>
			</div>
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">招考查询：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="school_exam_query" class="ace ace-switch ace-switch-7" type="checkbox" checked="" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div> -->
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">智学网：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="school_zhi_xue" class="ace ace-switch ace-switch-7" type="checkbox" checked="" value="1" />
						<span class="lbl"></span>
					</label>
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">功能模块：</label>
				<div class="col-sm-6">
					<?php foreach($menuList as $menu): ?>
					<div class="timeline-items mb20">
						<div class="timeline-item clearfix">
							<div class="widget-box transparent mg0">
								<div class="widget-header widget-header-small">
									<h5 class="widget-title smaller">
										<label>
											<input class="ace" type="checkbox" name="school_module_set" value="<?=$menu['id']?>" />
											<span class="lbl"></span>
										</label>
										<?=$menu['menu_name']?>
									</h5>
								</div>
								<div class="widget-body">
									<div class="widget-main"><?=$menu['menu_desc']?></div>
								</div>
							</div>
						</div>
					</div>
					<?php endforeach; ?>
				</div>
			</div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var provinceCode = <?=$schoolInfo ? $schoolInfo['school_province'] : 0?>;
	var cityCode = <?=$schoolInfo ? $schoolInfo['school_city'] : 0?>;
	var areaCode = <?=$schoolInfo ? $schoolInfo['school_area'] : 0?>;
	
	$(function(){
		// 提交表单
		var form = $("#school-form");
		var submitUrl = "<?=admin_url('admin/save_school_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('admin/school')?>";
				}
			});
		})
		// 省市区选择器
		$("#province-select").change(function(){
			show_city_list($(this).val());
		})
		$("#city-select").change(function(){
			show_area_list($(this).val());
		})
		// 如果有学校信息
		if(provinceCode) {
			$("#province-select").val(provinceCode);
			show_city_list(provinceCode);
		} else {
			show_city_list($("#province-select").val());
		}
		// 功能模块
		<?php if($schoolInfo): ?>
			<?php if($schoolInfo['school_module_set']): ?>
				var moduleArray = "<?=$schoolInfo['school_module_set']?>".split(",");
				for(var i in moduleArray) {
					$("[name=school_module_set][value="+ moduleArray[i] +"]").attr('checked', "checked");
				}
			<?php endif ?>	

			// 开关设置
			<?php if(!$schoolInfo['school_face_detect']): ?>$("[name=school_face_detect]").removeAttr("checked");<?php endif; ?>
			<?php if(!$schoolInfo['school_face_detect_type']): ?>$("[name=school_face_detect_type]").removeAttr("checked");<?php endif; ?>
			<?php if(!$schoolInfo['school_brand_update']): ?>$("[name=school_brand_update]").removeAttr("checked");<?php endif; ?>
			<?php if(!$schoolInfo['school_exam']): ?>$("[name=school_exam]").removeAttr("checked");<?php endif; ?>
			<?php if($schoolInfo['is_free_face_sdk']): ?>$("[name=face_sdk]").removeAttr("checked");<?php endif; ?>
			<?php if($schoolInfo['enable_teacher_sign']): ?>$("[name=enable_teacher_sign]").attr("checked", 'true');<?php endif; ?>

			<?php if(isset($schoolInfo['school_smart_lock'])): ?>
				<?php if(!$schoolInfo['school_smart_lock']): ?>$("[name=school_smart_lock]").removeAttr("checked");<?php endif; ?>
				<?php if($schoolInfo['school_smart_lock']): ?>$("[name=school_smart_lock]").attr("checked", 'true');<?php endif; ?>
			<?php endif ?>

			// 设置班牌主题
			$("[name=brand_theme]").val("<?= $schoolInfo['brand_theme'] ?>");
			// 设置人脸识别模块
			$("[name=school_face_detect]").val("<?= $schoolInfo['school_face_detect'] ?>");
			$("[name=school_face_detect_type]").val("<?= $schoolInfo['school_face_detect_type'] ?>");
			$("[name=expire_date]").val("<?= $schoolInfo['expire_date'] ?>");
			$("[name=face_similar]").val("<?= $schoolInfo['face_similar'] ?>");

		<?php endif; ?>
		// 日期时间选择器
		$('#datetime-picker').datetimepicker({
			format: 'YYYY-MM-DD',
			icons: {
				time: 'fa fa-clock-o',
				date: 'fa fa-calendar',
				up: 'fa fa-chevron-up',
				down: 'fa fa-chevron-down',
				previous: 'fa fa-chevron-left',
				next: 'fa fa-chevron-right',
				today: 'fa fa-arrows ',
				clear: 'fa fa-trash',
				close: 'fa fa-times'
			}
		}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});

		// 时间选择器
		$('#time-picker').timepicker({
				minuteStep: 1,
				showSeconds: false,
				showMeridian: false,
				disableFocus: true,
				icons: {
					up: 'fa fa-chevron-up',
					down: 'fa fa-chevron-down'
				}
			}).on('changeTime.timepicker', function(e) {
				var target = e.currentTarget;
				$(target).text(e.time.value)
			});
		})

	var areaDataUrl = "<?=admin_url('api/get_area_list')?>";
	// 显示城市列表
	function show_city_list(code) {
		$("#city-select").empty();
		ajax_get(areaDataUrl + "/" + code, {hideLoading: true}, function(res) {
			for(var i in res.data) $("#city-select").append('<option value="'+ res.data[i].area_code +'">'+ res.data[i].area_name +'</option>');
			// 获取区域列表
			if(cityCode) {
				$("#city-select").val(cityCode);
				show_area_list(cityCode)
			} else {
				show_area_list($("#city-select").val());
			}
		})
	}
	// 显示区域列表
	function show_area_list(code) {
		$("#area-select").empty();
		ajax_get(areaDataUrl + "/" + code, {hideLoading: true}, function(res) {	
			if(res.data.length > 0) {
				$("#area-select").show();
				for(var i in res.data) $("#area-select").append('<option value="'+ res.data[i].area_code +'">'+ res.data[i].area_name +'</option>');
				if(areaCode) {
					$("#area-select").val(areaCode);
				}
			} else {
				$("#area-select").hide();
			}
		})
	}
</script>